package com.zwl.swagger;

import com.google.common.collect.Lists;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhangweilin
 * @date 2019/6/21 9:41
 * @Description: 系统配置
 */
@Component
@Configuration
@ConfigurationProperties(prefix = "swagger")
@Data
public class SwaggerProperties {


    private Swagger2Properties core =new Swagger2Properties();

    @Data
    public static class Swagger2Properties {

        private String tokenKey = "Authorization";


		/**
		 * 全局header,除了token，比如区域boss的areaId
		 */
		private List<String> globalHeaderKey;


		/**
		 * 审计字段，如创建时间创建人之类的
		 */
		private List<String> auditField;

		/**
		 * 是否开启swagger文档
		 */
		private boolean docSwitch=true;


		public List<String> getGlobalHeaderKey() {
			List<String> globalHeaderList = Lists.newArrayList(tokenKey);
			if (!CollectionUtils.isEmpty(globalHeaderKey)) {
				globalHeaderList.addAll(globalHeaderKey);
			}
			return globalHeaderList;
		}


		public List<String> getAuditField() {
			if (auditField == null || auditField.isEmpty()) {
				auditField = new ArrayList<>();
				auditField.add("createUserId");
				auditField.add("createUserName");
				auditField.add("modifyUserId");
				auditField.add("modifyUserName");
				auditField.add("tmCreate");
				auditField.add("tmSmp");
			}
			return auditField;
		}

		/**
         * swagger文档basePackage,支持ant风格路径，如sys.swagger.base-packages=com.frxs.**.controller**,com.frxs.xxx.controller**,com.frxs.common.controller
         */
        private List<String> basePackages= Lists.newArrayList("com.frxs.**.controller**","com.zwl.**.controller**");

        private Info info=new Info();

        @Data
        public static class Info {
            private String title="卜米api";
            private String description="卜米api";
            private String termsOfServiceUrl;
            private String version="1.0";
            private String license="The Apache License, Version 2.0";
            private String licenseUrl="http://www.apache.org/licenses/LICENSE-2.0.html";
            private Contact contact=new Contact();

            @Data
            public static class Contact {
                private String name="";
                private String url="";
                private String email="";
            }

        }
    }
}
